package eleanor.ltd.isRealEstate.dao.estate;

import java.util.List;

import javax.inject.Inject;

import org.apache.tapestry5.annotations.Log;
import org.hibernate.Session;

import eleanor.ltd.isRealEstate.entities.estate.Estate;
import eleanor.ltd.isRealEstate.entities.user.User;


public class EstateDAOImpl implements EstateDAO {

	@Inject
	private Session session;

	@Log
	public boolean save(Estate estate) {
		if (estate != null) {
			session.save(estate);
			return true;
		}
		return false;
	}

	@Log
	public boolean delete(Estate estate) {
		if (estate != null) {
			session.delete(estate);
			return true;
		}
		return false;
	}

	@Log
	public boolean update(Estate estate) {
		if (estate != null) {
			session.update(estate);
			return true;
		}
		return false;
	}

	@Log
	public List findAll() {
		return session.createCriteria(Estate.class).list();
	}

	@Log
	public boolean deleteByID(Long id) {
		Estate u = findByID(id);
		if (u != null) {
			delete(u);
			return true;
		}
		return false;
	}

	@Log
	public Estate findByID(Long id) {
		if (id != null) {
			return (Estate) session.load(Estate.class, id);
		}
		return null;
	}
	
}
